package olap4cloud.hbase.util;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;

public class MyHadoopJob {

	private Configuration conf  = new Configuration();
	Job job = null;
	
	public void setConfig(Configuration myconf){
		conf = myconf;
	}
	
	public void setDebug(){
		conf.set("mapred.job.tracker", "local");
	}
	
	public void setQueueName( String queuename){
		conf.set("mapred.job.queue.name", queuename);
	}
	
	
	public void set(String name , String value){
		conf.set(name, value);
	}
	
	public void setInt(String name , int value){
		conf.setInt(name, value);
	}
	
	public final int  MAXFAIL = 10;
	
	public void setMaxFailMap(){
		conf.set("mapreduce.map.failures.maxpercent", String.valueOf(MAXFAIL));
		conf.set("mapred.max.map.failures.percent", String.valueOf(MAXFAIL));
	}
	
	public Job getJobBase(Class<?> MyClass, String jobname, String queuename) throws IOException{
		
		setMaxFailMap();
		setQueueName( queuename);
		
		if (job == null)
			job = new Job(conf);
		job.setJarByClass(MyClass);
		job.setJobName(jobname);
		return job;
	}
	
	public Job getJobBase(Class<?> MyClass, String jobname) throws IOException{
		
		setMaxFailMap();
		
		if (job == null)
			job = new Job(conf);
		
		job.setJarByClass(MyClass);
		job.setJobName(jobname);
		return job;
	}
}
